Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AEP: extending the REST API to support mutating (POST) queries #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NinadBhat
Copy link

Have kept the status as "draft".

  • Used AEP template from AEP 0
  • Status is submitted
  • Added type & status labels to PR
  • Added AEP to README.md
  • Provided github handles for authors

@chrisjsewell chrisjsewell changed the title Adds AEP for extending API Adds AEP for extending REST API May 3, 2021
@ltalirz
Copy link
Member

ltalirz commented May 3, 2021

thanks @NinadBhat - I'll go through the PR tomorrow

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @NinadBhat and sorry for the delay.

this looks good as a first draft, here comes my first review

|------------|------------------------------------------------------------------|
| Title | Extending the AiiDA REST API towards workflow management |
| Authors | [Ninad Bhat](mailto:[email protected]) (NinadBhat) |
| Champions | [Leopold Talirz](mailto:[email protected]) (Italirz) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Champions | [Leopold Talirz](mailto:[email protected]) (Italirz) |
| Champions | [Leopold Talirz](mailto:[email protected]) (ltalirz) |


The Proposal is to make three additions to AiiDA REST API.

1. Add JSON schema validation and implementing authorisation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Add JSON schema validation and implementing authorisation
1. Add validation of the QueryBuilder JSON using JSON schema
1. Add authentication/authorisation

Comment on lines 22 to 23
2. Add POST methods to /users, /computers, /nodes and /groups endpoint
3. Creating a new /processes endpoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Add POST methods to /users, /computers, /nodes and /groups endpoint
3. Creating a new /processes endpoint
1. Add POST methods to /users, /computers, /nodes and /groups endpoints
1. Add a new /processes endpoint

## Detailed Explanation

### Schema Validation and Authorisation
Currently, only QueryBuilder endpoint has a post method. Post endpoint for QueryBuilder was implemented in [PR #4337](https://github.com/aiidateam/aiida-core/pull/4337). The current implementation only checks if the posted JSON is a dict at [L269](https://github.com/aiidateam/aiida-core/blob/develop/aiida/restapi/resources.py#L269).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Currently, only QueryBuilder endpoint has a post method. Post endpoint for QueryBuilder was implemented in [PR #4337](https://github.com/aiidateam/aiida-core/pull/4337). The current implementation only checks if the posted JSON is a dict at [L269](https://github.com/aiidateam/aiida-core/blob/develop/aiida/restapi/resources.py#L269).
Currently, only the `/querybuilder` endpoint accepts `POST` requests (implemented in [PR #4337](https://github.com/aiidateam/aiida-core/pull/4337)).
The current implementation only checks if the posted JSON is a `dict` (see [L269](https://github.com/aiidateam/aiida-core/blob/develop/aiida/restapi/resources.py#L269)).


## Detailed Explanation

### Schema Validation and Authorisation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's split this into two since they are really different aspects and can be addressed independently


```

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this information already exists in the translators
https://github.com/aiidateam/aiida-core/blob/5f50f0335761386ddacbb5de4a6934b659b20e2d/aiida/restapi/translator/user.py#L40-L69

We should reuse this, i.e. either generate the JSON schema from the projectable_properties or vice versa (to think about).

Furthermore, the JSON schema should contain the "required" field with information on whether each of the respective fields

```

{
"first_name": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want/need to add some extra metadata around

I would have thought more something like

{
  "$id": "https://raw.githubusercontent.com/aiidateam/aiida-core/master/aiida/restapi/schemas/user.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "User",
  "type": "object",
  "properties": {
    "first_name": {
      "type": "string",
      "description": "The person's first name."
    }
   ...
}

},
"extras": {
"description": ""
"type": "json object"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"type": "json object"
"type": "object"

}
"attributes": {
"description": "attributes of the node"
"type": "json object"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"type": "json object"
"type": "object"


### Cons
1. Development time spent on extending API
2. Also the time spent on maintaining API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Also the time spent on maintaining API
2. Increased maintenance effort for the REST API for changes in the ORM
The second point could be minimized by aiming for a single source for the attributes of the ORM entities that is used both by the python API and the REST API.

@chrisjsewell
Copy link
Member

A few extra things to add:

  1. Adding/removing (existing) nodes to (existing) groups. This should be pretty and easy and would be incredibly useful (e.g. to quickly "bookmark" certain nodes whilst explore a database)
  2. Access (and modification of) equivalent data to verdi settings list, i.e. all the setting for the verdi profile

@sphuber sphuber changed the title Adds AEP for extending REST API AEP: extending the REST API to support mutating (POST) queries Dec 16, 2021
@sphuber sphuber added status/draft type/standard Standard Track AEP labels Dec 16, 2021
@ltalirz
Copy link
Member

ltalirz commented Nov 2, 2022

Prototype implementation in https://github.com/aiidateam/aiida-restapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants